package com.itheima.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

//@Component
//@Aspect
@Slf4j
@Order(2)
public class ATimeAspect {
    //重复的逻辑
    @Around("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public Object timeRecord(ProceedingJoinPoint joinPoint) throws Throwable {
        //开始时间
        long t1 = System.currentTimeMillis();
        //洗菜，切菜，xxxx 准备工作

        //TODO 调用原始方法
        Object result = joinPoint.proceed(); //炒菜
        //结束时间
        //洗锅
        long t2 = System.currentTimeMillis();
        log.info("花费时间：{} ms", (t2 - t1));
        return result;
    }

    @Before("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void beforeAdvice() {
        log.error("******AAAAA beforeAdvice*******2222");
    }

    @After("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void afterAdvice() {
        log.error("******AAA afterAdvice*******2222");

    }

    @AfterReturning("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void afterReturningAdvice() {
        log.error("******AAAA afterReturningAdvice*******22222");

    }

    @AfterThrowing("execution(* com.itheima.service.impl.DeptServiceImpl.*(..))")
    public void afterThrowingAdvice() {
        log.error("AAAAA ******afterThrowingAdvice*******22222");
    }

}














